using System;
using System.Windows.Forms;
using Microsoft.Win32;
public class StartupManager : Form
{
// The path to the key where Windows looks for startup applications
static RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
/// <summary>
/// Checking if the startup is already enabled or not
/// </summary>
/// <returns>Returns the state of the startup</returns>
public static bool IsStartupInitialized()
{
return rkApp.GetValue(Application.ProductName) != null;
}
/// <summary>
/// Changing the app startup state
/// </summary>
/// <param name="to">Set startup state to</param>
public void SetStartupState(bool to)
{
if (to)
{
// Add the value in the registry so that the application runs at startup
rkApp.SetValue(Application.ProductName, Application.ExecutablePath);
}
else
{
// Remove the value from the registry so that the application doesn't start
rkApp.DeleteValue(Application.ProductName, false);
}
}
}